package com.charon.auth.common.entity;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
  *@ClassName: ImageCode
  *@Description: 图片验证码
  *@Author: Charon [248135724@qq.com]
  *@Date: 2019/1/29 0029 10:58
  *@Version: 1.0
  */
public class ImageCode {

    /**
     * 验证码图片
     */
    private BufferedImage image;

    /**
     * 验证码
     */
    private String code;

    /**
     * 验证码过期时间
     */
    private LocalDateTime expireTime;

    /**
     * @param image  验证码图片
     * @param code  验证码
     * @param expire  多少秒后过期
     */
    public ImageCode(BufferedImage image,String code,int expire){
        this.image=image;
        this.code=code;
        this.expireTime=LocalDateTime.now().plusSeconds(expire);
    }

    /**
     * @param image  验证码图片
     * @param code  验证码
     * @param expire  过期时间
     */
    public ImageCode(BufferedImage image,String code,LocalDateTime expire){
        this.image=image;
        this.code=code;
        this.expireTime=expire;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    /**
     * @Description 判断当前时间是否在验证码过期时间之后，true：已过期
     * @Author Charon [248135724@qq.com]
     * @Date 2019/1/29 23:54
     * @Param []
     * @return boolean true：过期  false：未过期
     */
    public boolean isExpried(){
        return LocalDateTime.now().isAfter(expireTime);
    }
}
